var common = require('../../utils/common.js') //引用公共JS文件
Page({
  data:{
    userInfo: {},
    hasUserInfo: false,
    canIUseGetUserProfile: false,
    nickName:'未登录',
    src:'/images/index.png',
    newList:[{
      id: '264698',
      title: '省退役军人事务厅来校交流对接工作',
      poster: 'https://gaopursuit.oss-cn-beijing.aliyuncs.com/2022/newsimage1.jpg',
      add_date: '2022-08-19'
    
    }]
  },
  
  getLoginCode() {
		return new Promise((resolve, reject) => {
			wx.login({
				success(res) {
					resolve(res.code)
				},
				fail(err) {
					reject(err)
				}
			})
		})
	},

  getMyInfo:function(e){
    wx.getUserProfile({
      desc: '获取信息',
     
      success:res=>{
      
        console.log(res.userInfo)
        let info = res.userInfo;
        this.setData({
          isLogin:true,
          src:info.avatarUrl,
          nickName:info.nickName
        });
        this.getMyFavorites();
      },
  


    })
  },
  onShow() {
    if(this.data.isLogin){
      this.getMyFavorites()
    }
  },
  goToDetail:function(e){
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../detail/detail?id='+id,
    })
 },
 getMyFavorites:function(){
  let info = wx.getStorageInfoSync();
  let keys = info.keys;
  let num = keys.length;

  let myList = [];
  for(var i = 0;i<num;i++){
    let obj = wx.getStorageSync(keys[i]);
    myList.push(obj);
  }
  this.setData({
    newsList:myList,
    num:num
  });
},
onLoad: function() {
  this.getMyInfo();
},
})